﻿var baseUrl = "../Server/BaseService.ashx?model=";
function IsNotNullOrEmpty(value) {
    var reg = /^\s*$/
    //返回值为true表示不是空字符串
    return (value != null && value != undefined && !reg.test(value))
}
//path：文件相对路径，filename：文件名称
function downLoad(path, filename) {
    $.ajax({
        type: 'post',
        url: baseUrl + "GetFileB",
        data: { URL: path },
        success: function(res) {
            var result = $.parseJSON(res);
            if (result.code == 0) {
                return;
            }
            var bstr = atob(result.data, "utf-8"),
                n = bstr.length;
            //                                var arr = window.atob(result.data);
            var u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n) // 转换编码后才可以使用charCodeAt 找到Unicode编码
            }
            var blob = new Blob([u8arr]); //application/vnd.openxmlformats-officedocument.wordprocessingml.document这里表示doc类型
            var href = window.URL.createObjectURL(blob); //创建下载的链接var uInt8Array = new Uint8Array(res.data);

            if (window.navigator.msSaveBlob) { //ie
                try {
                    window.navigator.msSaveBlob(blob, filename)
                } catch (e) {
                    console.log(e);
                }
            } else {
                // 谷歌浏览器 创建a标签 添加download属性下载
                var downloadElement = document.createElement('a');
                downloadElement.href = href;
                downloadElement.target = '_blank';
                downloadElement.download = filename; //下载后文件名
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放掉blob对象
            }
        }
    });
}
//path：文件相对路径
function DeleteFile(path) {
    if (!CheckIsNullOrEmpty(path))
        return;
    $.ajax({
        type: 'post',
        url: baseUrl + "DeleteFile",
        data: { URL: path },
        success: function(res) {
            var result = $.parseJSON(res);
            if (result.code == 1) {
                //已删除对应文件
            }
        }
    });
}

//验证手机号
function isPhone(val) {
    var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/; //手机号码
    var isMob = /^0?1[3|4|5|8][0-9]\d{8}$/; // 座机格式
    if (isMob.test(val) || isPhone.test(val)) {
        return true;
    } else {
        return false;
    }
}
//验证身份证
function isCardNo(card) {
    // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (reg.test(card) === false) {
        return false;
    } else {
        return true;
    }
}

//验证邮箱
function isEmail(num) {
    var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
    if (reg.test(num) === false) {
        return false;
    } else {
        return true;
    }
}

function ShowImg(src) {
    layer.photos({
        photos: {
            "title": "", //相册标题
            "id": 123, //相册id
            "start": 0, //初始显示的图片序号，默认0
            "data": [{ "alt": "图片名", "pid": 666, "src": src, "thumb": "" }]
        },
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
}

function getobj(id) {
    var elms = $("#" + id + " [name]"); //formid 包含name属性的所有元素
    var obj = {};
    $.each(elms, function(i, item) {
        var name = $(item).attr("name");
        if ($(item).attr("type") != "radio")
            obj[name] = "";
    });
    return obj;
}
//获取url的参数值
function getUrlData(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(unescape(r[2]));
    }
    return null;
}

function SetCookie(cookieName, cookieValue, nDays) { //设置cookie
    var today = new Date(),
        expire = new Date(); /*当前日期*/ /*Cookie过期时间*/
    if (nDays == null || nDays == 0) nDays = 1; /*如果未设置nDays参数或者nDays为0，取默认值1*/
    expire.setTime(today.getTime() + 3600000 * 24 * nDays); /*计算Cookie过期时间*/
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString(); /*设置Cookie值*/
}

function ReadCookie(cookieName) { //获取登录界面传过来的cookie
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf(cookieName);
    if (ind == -1 || cookieName == "") return "";
    var ind1 = theCookie.indexOf(';', ind);
    if (ind1 == -1) ind1 = theCookie.length;
    return unescape(theCookie.substring(ind + cookieName.length + 1, ind1)); /*读取Cookie值*/
}
//初始化菜单滚动
function initMenuScroll() {
    var dparent = document.getElementById('menuDiv');
    var dchild = document.getElementById('menu');
    var count = $("#menu").children("li").length;
    if (dparent.clientWidth < dchild.clientWidth || dparent.clientWidth == dchild.clientWidth) {
        //ff用
        objAddEvent(dchild, 'DOMMouseScroll', function(e) { return mouse_scroll(e, dparent, 1); })
            //chrome用
        objAddEvent(dchild, 'mousewheel', function(e) { return mouse_scroll(e, dparent, 1); })
    } else {
        //ff用
        objAddEvent(dchild, 'DOMMouseScroll', function(e) { return false; })
            //chrome用
        objAddEvent(dchild, 'mousewheel', function(e) { return false; })
    }
}
//初始化菜单滚动
function initMenuScroll2() {
    var dparent = document.getElementById('chidmenuDiv');
    var dchild = document.getElementById('chidmenu');
    var count = $("#chidmenu").children("li").length;
    if (dparent.clientHeight < dchild.clientHeight || dparent.clientHeight == dchild.clientHeight) {
        //ff用
        objAddEvent(dchild, 'DOMMouseScroll', function(e) { return mouse_scroll(e, dparent, 2); })
            //chrome用
        objAddEvent(dchild, 'mousewheel', function(e) { return mouse_scroll(e, dparent, 2); })
    } else {
        //ff用
        objAddEvent(dchild, 'DOMMouseScroll', function(e) { return false; })
            //chrome用
        objAddEvent(dchild, 'mousewheel', function(e) { return false; })
    }
}
//这个是给对象增加监控方法的函数
function objAddEvent(oEle, sEventName, fnHandler) {
    if (oEle.attachEvent) oEle.attachEvent('on' + sEventName, fnHandler);
    else oEle.addEventListener(sEventName, fnHandler, false);
}
//控制div左右或上下滚动p:父元素
function mouse_scroll(e, p, t) {
    e = e || window.event;
    var delD = e.wheelDelta ? e.wheelDelta : -e.detail * 40; //判断上下方向
    var move_s = delD > 0 ? -50 : 50;
    if (t == 1) {
        document.documentElement.scrollLeft += move_s; //非chrome浏览器用这个
        //chrome浏览器用这个
        if (document.documentElement.scrollLeft == 0) p.scrollLeft += move_s;
    } else {
        document.documentElement.scrollTop += move_s; //非chrome浏览器用这个
        //chrome浏览器用这个
        if (document.documentElement.scrollTop == 0) p.scrollTop += move_s;
    }
    return false;
}

function showform(type) {
    if (type == 1) {
        $(".page_field").eq(0).css("display", "none");
        $(".page_field").eq(1).css("display", "flex");
    } else {
        $(".allbody").eq(0).css("display", "none");
        $(".allbody").eq(1).css("display", "flex");
    }
}

function hideform(type) {
    if (type == 1) {
        $(".page_field").eq(1).css("display", "none");
        $(".page_field").eq(0).css("display", "flex");
    } else {
        $(".allbody").eq(1).css("display", "none");
        $(".allbody").eq(0).css("display", "flex");
    }
}
//绑定输入信息界面的收缩展开按钮事件
function bindheader() {
    $(".form_header i").on("click", function() {
        if ($(this).hasClass("layui-icon-subtraction")) {
            $(this).removeClass("layui-icon-subtraction");
            $(this).parent().next().slideUp();
        } else {
            $(this).addClass("layui-icon-subtraction");
            $(this).parent().next().slideDown();
        }
    })
}
//绑定基础下拉框：name-下拉框的name，code-字典表的Type_Code，调用示例bindBasicSelect("level","CDDJ")绑定菜单等级
function bindBasicSelect(name, code) {
    var param = { Type_Code: code };
    //"GetSysBasicByTypeCode"是示例的服务接口名，可更改
    bindSelect(name, "GetSysBasicByTypeCode", param);
}
//绑定所有下拉框：name-下拉框的name，model-服务端接口，parme-参数，调用示例bindBasicSelect("menu","getmenu",{ParentID:0})绑定菜单
function bindSelect(name, model, parme) {
    var $this = $("select[name='" + name + "']");
    $this.empty();
    $.ajax({
        type: "GET",
        url: baseUrl + model,
        async: false,
        data: parme,
        success: function(result) {
            var lresult = $.parseJSON(result);
            if (lresult.code == 1) {
                var data = eval(lresult.data);
                $this.append('<option value="">请选择</option>')
                for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                    $this.append('<option value="' + data[i].CODE + '">' + data[i].NAME + '</option>')
                }
            } else {
                layer.msg(lresult.msg);
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

function bindSelect2(controlName, Url, method, parme) {
    var $this = $("select[name='" + controlName + "']");
    //    $this.empty();//清空所以子节点
    $.ajax({
        type: "GET",
        url: Url + method,
        async: false,
        data: parme,
        success: function(result) {
            var lresult = $.parseJSON(result);
            if (lresult.code == 1) {
                var data = eval(lresult.data);
                $this.append('<option value="">请选择</option>')
                for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                    $this.append('<option value="' + data[i].CODE + '">' + data[i].NAME + '</option>')
                }
            } else {
                layer.msg(lresult.msg);
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

//#region 省市县联动 

function bindProvinceSelect(name) {
    var $this = $("select[name='" + name + "']");
    $this.empty();
    $.ajax({
        type: "GET",
        url: baseUrl + "GetProvince",
        async: false,
        success: function(result) {
            var lresult = $.parseJSON(result);
            var data = eval(lresult);
            for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                $this.append('<option value="' + data[i].id + '">' + data[i].label + '</option>')
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

function bindCitySelect(name, Province_id) {
    var $this = $("select[name='" + name + "']");
    $this.empty();
    $.ajax({
        type: "GET",
        url: baseUrl + "GetCity&ProvinceID=" + Province_id,
        async: false,
        success: function(result) {
            var lresult = $.parseJSON(result);
            var data = eval(lresult);
            for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                $this.append('<option value="' + data[i].id + '">' + data[i].label + '</option>')
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

function bindCountySelect(name, city_id) {
    var $this = $("select[name='" + name + "']");
    $this.empty();
    $.ajax({
        type: "GET",
        url: baseUrl + "GetCounty&CityID=" + city_id,
        async: false,
        success: function(result) {
            var lresult = $.parseJSON(result);
            var data = eval(lresult);
            for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                $this.append('<option value="' + data[i].id + '">' + data[i].label + '</option>')
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

function GetAreaByID(name, ParentID, leval_name) {
    var $this = $("select[name='" + name + "']");
    $this.empty();
    $.ajax({
        type: "GET",
        url: baseUrl + "GetAreaByID&ParentID=" + ParentID + "&LevelName=" + leval_name,
        async: false,
        success: function(result) {
            var lresult = $.parseJSON(result);
            var data = eval(lresult);
            for (var i = 0; i < data.length; i++) { //data[i].CODE对应value字段，data[i].NAME对应显示的文字字段
                $this.append('<option value="' + data[i].id + '">' + data[i].label + '</option>')
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

function getDropProvince(ProvinceID) {
    var Province = [];
    $.ajaxSettings.async = false;
    $.post(baseUrl + 'GetProvince&ProvinceID=' + ProvinceID, function(data) {

        var res = JSON.parse(data)

        Province = JSON.parse(JSON.stringify(res).toString());

    })
    $.ajaxSettings.async = true;
    return Province;
}

function getDropArea(ParentID, leval_name) {
    var Area = [];
    $.ajaxSettings.async = false;
    $.post(baseUrl + "GetAreaByID&ParentID=" + ParentID + "&LevelName=" + leval_name, function(data) {

        var res = JSON.parse(data)

        Area = JSON.parse(JSON.stringify(res).toString());

    })
    $.ajaxSettings.async = true;
    return Area;
}
//#endregion

var data1 = [{
    title: '行政部门',
    id: 1,
    children: [{
        title: '部门001',
        id: 1000,
        children: [{
            title: '小组一',
            id: 10001
        }, {
            title: '小组二',
            id: 10002
        }]
    }, {
        title: '部门002',
        id: 1001
    }, {
        title: '部门003',
        id: 1002
    }]
}];
//绑定所有tree
function bindTree(id, model, parme) {
    $.ajax({
        type: "GET",
        url: baseUrl + model,
        async: false,
        data: parme,
        success: function(result) {
            var lresult = $.parseJSON(result);
            if (lresult.code == 1) {
                var datas = eval(lresult.data);
                layui.tree.reload(id, {
                    nodes: datas
                });
            } else {
                layer.msg(lresult.msg);
            }
        },
        error: function(XMLHttpRequest, textStatuss, errorThrown) {
            layer.msg(XMLHttpRequest.responseText);
        },
        beforeSend: function(xmlHttp) {
            xmlHttp.setRequestHeader("If-Modified-Since", "0");
            xmlHttp.setRequestHeader("Cache-Control", "no-cache");
        }
    })
}

//正则表达式用于判斷字符串是否全部由空格或换行符组成
function CheckIsNullOrEmpty(value) {
    var reg = /^\s*$/
        //返回值为true表示不是空字符串
    return (value != null && value != undefined && !reg.test(value))
}

function clock() {
    var d = new Date();
    $("#time").text((d.getHours() < 10 ? "0" + d.getHours() : d.getHours()) + ":" + (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes()) + ":" + (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds()));
}

function getCurrentDate() {
    var myDate = new Date();
    var year = myDate.getFullYear(); //年
    var month = myDate.getMonth() + 1; //月
    var day = myDate.getDate(); //日
    var days = myDate.getDay();
    switch (days) {
        case 1:
            days = '星期一';
            break;
        case 2:
            days = '星期二';
            break;
        case 3:
            days = '星期三';
            break;
        case 4:
            days = '星期四';
            break;
        case 5:
            days = '星期五';
            break;
        case 6:
            days = '星期六';
            break;
        case 0:
            days = '星期日';
            break;
    }
    var str = year + "年" + month + "月" + day + "日  ";
    $("#year").text(str);
    $("#week").text(days);
}


function bindSSWG() {
    //#region 所属网格

    window.data = {
        ischecked: true,
        setValue: function(el) {
            this.ischecked = true;
            var val = el.dataset.value;
            $("#SSWG").val(val);
        }
    }
    var SSWGel = layui.eleTree.render({
        elem: '#SSWGtree',
        data: getDropProvince(),
        showCheckbox: false,
        lazy: true,
        load: function(data, callback) {
            //console.log(data);
            var newData;
            switch (data.leval) {
                case 1:
                    newData = getDropArea(data.id, "city");
                    break;
                case 2:
                    newData = getDropArea(data.id, 'county')
                    break;
                case 3:
                    newData = getDropArea(data.id, 'town')
                    break;
                case 4:
                    newData = getDropArea(data.id, 'village')
                    break;
                default:
                    break;
            }
            setTimeout(function() {
                callback(newData);
            }, 50);

        },
        highlightCurrent: true,
        defaultExpandedKeys: ["450"],
        done: function() {}
    });
    layui.eleTree.on("nodeClick(SSWGtree)", function(d) {
        //alert(d.data.currentData.label + "[" + d.data.currentData.id + "]")
        $("#SSWG").val(d.data.currentData.label + "[" + d.data.currentData.id + "]");
        data.ischecked = true;
    })
    $("body").on("click", function(event) {
        if (data.ischecked == false) {
            $("#SSWG").val("");
        }
        $("#dropList").hide();
        event.stopPropagation();
    })
    $("#SSWG").on("click", function(event) {
        data.ischecked = false;
        $("#SSWG").val("");
        $("#dropList").show();
        $("#dropSSWGtree").show();
        $("#dropSSWGSelect").hide();
        //$("div [data-id=450400000000]").find("span")[0].click()
        scrollTopToDom($("#SSWGtree"), $("#SSWGtree [data-id=450400000000]").find("span").eq(0))


        function scrollTopToDom($scrollDom, $scrollToDom) {
            var topOffsetPx = $("#SSWGtree").offset().top;

            var domOffsetPx = $scrollToDom.height() * 32;
            //var px = $scrollToDom.offset().top - topOffsetPx;
            // 目标元素相对于文档偏移量 - 第一个元素相对于文档偏移量 就是滚动条要滚动的距离
            var scrollTopPx = domOffsetPx - topOffsetPx;
            $scrollDom.scrollTop(scrollTopPx); // 如果不用动画，也可以用这个进行直接定位
        }
        event.stopPropagation();
    })
    $("#SSWG").keypress(function(event) {
        if (event.keyCode == 13) {
            var loading = layer.msg('正在加载', {
                icon: 16,
                shade: 0.3,
                time: 0
            });
            var sswg = $("#SSWG").val();
            $.ajax({
                url: baseUrl + "GetAreaByName",
                data: { "word": sswg },
                success: function(data) {
                    layer.close(loading);
                    var res = JSON.parse(data);
                    $("#SSWGSelect").empty();
                    if (res.length == 0) {
                        $("#SSWGSelect").append("<input style='margin:0px'" +
                            "class='area layui-btn layui-btn-primary  layui-btn-fluid' type='button' value='无数据'></input>");
                    }
                    for (var a in res) {
                        $("#SSWGSelect").append("<input style='margin:0px' onclick='data.setValue(this)' class='area layui-btn layui-btn-primary  layui-btn-fluid' type='button' data-value='" +
                            res[a].label + "[" + res[a].id + "]" + "' value='" + res[a].fullname + "'></input>");
                    }
                }
            })
        }
        //$("#dropList").show();
        $("#dropSSWGtree").hide();
        $("#dropSSWGSelect").show();
        layui.form.render();
        event.stopPropagation();
    })



    $("#SSWGtree [data-id=450]").find("span")[0].click()
    setTimeout(function() {
        $("#SSWGtree [data-id=450400000000]").find("span")[0].click();
    }, 500);






    //如果该元素没有什么父级元素可以直接这样

    //        div1.style.left = element.style.left;

    //        div1.style.top = element.style.top
    //#endregion


}

function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if (isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if (fIEVersion == 7) {
            return 7;
        } else if (fIEVersion == 8) {
            return 8;
        } else if (fIEVersion == 9) {
            return 9;
        } else if (fIEVersion == 10) {
            return 10;
        } else {
            return 6; //IE版本<=7
        }
    } else if (isEdge) {
        return 'edge'; //edge
    } else if (isIE11) {
        return 11; //IE11  
    } else {
        return -1; //不是ie浏览器
    }
}

//比较两个对象是否想等
function deepCompare(x, y) {
    var i, l, leftChain, rightChain;

    function compare2Objects(x, y) {
        var p;

        // remember that NaN === NaN returns false
        // and isNaN(undefined) returns true
        if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
            return true;
        }

        // Compare primitives and functions.     
        // Check if both arguments link to the same object.
        // Especially useful on the step where we compare prototypes
        if (x === y) {
            return true;
        }

        // Works in case when functions are created in constructor.
        // Comparing dates is a common scenario. Another built-ins?
        // We can even handle functions passed across iframes
        if ((typeof x === 'function' && typeof y === 'function') ||
            (x instanceof Date && y instanceof Date) ||
            (x instanceof RegExp && y instanceof RegExp) ||
            (x instanceof String && y instanceof String) ||
            (x instanceof Number && y instanceof Number)) {
            return x.toString() === y.toString();
        }

        // At last checking prototypes as good as we can
        if (!(x instanceof Object && y instanceof Object)) {
            return false;
        }

        if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
            return false;
        }

        if (x.constructor !== y.constructor) {
            return false;
        }

        if (x.prototype !== y.prototype) {
            return false;
        }

        // Check for infinitive linking loops
        if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
            return false;
        }

        // Quick checking of one object being a subset of another.
        // todo: cache the structure of arguments[0] for performance
        for (p in y) {
            if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
                return false;
            } else if (typeof y[p] !== typeof x[p]) {
                return false;
            }
        }

        for (p in x) {
            if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
                return false;
            } else if (typeof y[p] !== typeof x[p]) {
                return false;
            }

            switch (typeof(x[p])) {
                case 'object':
                case 'function':

                    leftChain.push(x);
                    rightChain.push(y);

                    if (!compare2Objects(x[p], y[p])) {
                        return false;
                    }

                    leftChain.pop();
                    rightChain.pop();
                    break;

                default:
                    if (x[p] !== y[p]) {
                        return false;
                    }
                    break;
            }
        }

        return true;
    }

    if (arguments.length < 1) {
        return true; //Die silently? Don't know how to handle such case, please help...
        // throw "Need two or more arguments to compare";
    }

    for (i = 1, l = arguments.length; i < l; i++) {

        leftChain = []; //Todo: this can be cached
        rightChain = [];

        if (!compare2Objects(arguments[0], arguments[i])) {
            return false;
        }
    }

    return true;
}

//删除对象数组中的某一个对象
function delitem(arr, text) {

    for (let i = 0; i < arr.length; i++) {

        if (deepCompare(text, arr[i])) {

            console.log('找到了：' + arr[i] + '下标：' + i);

            //查找到以后执行删除

            arr.splice(i, 1);

            //splice参数说明：第一个参数是要删除的下标，第二个是删除下标后面的几条数据，包括自己，写1就是删除自身一个，要是2它会把自身和后面的一位也删掉

            //如果数组里要是有多个元素是同样的值，就把下面return false;注释掉，不然只会删除最前面的一个元素

            return false;

        } else {

            console.log('没找到：' + text);

        }

    }

}

function getDeviceParent() {
    var Province = [];
    $.ajaxSettings.async = false;
    $.post(baseUrl + 'GetDeviceParent', function(data) {
        var res = JSON.parse(data)

        Province = JSON.parse(JSON.stringify(res).toString());

    })
    $.ajaxSettings.async = true;
    return Province;
}

function getDeviceChildren(id) {
    var Province = [];
    $.ajaxSettings.async = false;
    $.post(baseUrl + 'GetDeviceChildren&KeyID=' + id, function(data) {
        var res = JSON.parse(data)

        Province = JSON.parse(JSON.stringify(res).toString());

    })
    $.ajaxSettings.async = true;
    return Province;
}